package com.zbs.framework.common.weixin;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: Zbs
 * @create: 2020-10-23 12:22
 */
@Configuration
public class WxApiConfig {

    @Bean
    @DependsOn("constantWxUtils")
    public WxMpService myWxMpService(){
        WxMpDefaultConfigImpl configStorage = new WxMpDefaultConfigImpl();
        configStorage.setAppId(ConstantWxUtils.appId);
        configStorage.setSecret(ConstantWxUtils.appSecret);
        configStorage.setAesKey(ConstantWxUtils.appAseKey);
        configStorage.setToken(ConstantWxUtils.appToken);
        Map<String, WxMpConfigStorage> mp = new HashMap<>();
        mp.put(ConstantWxUtils.appId,configStorage);

        WxMpService service = new WxMpServiceImpl();
        service.setMultiConfigStorages(mp);
        return service;
    }
}
